
angular.module('newsmorecontrollers', [])
    .controller("NewsMoreCtrl",function($scope,$state,$rootScope,$timeout,$ionicSlideBoxDelegate,Loading,ENV,News,Storage){
        //图片路径
        $scope.picPath = ENV.picPath;

        //== 暂时id start ==
        $scope.result = {
            member_id : 626
        };
        //== 暂时id begin ==


        //返回
        $scope.goback = function(){
            History.goback();
        };
        $scope.$on('$ionicView.beforeEnter', function () {
            $rootScope.showWineGlasses = false;

            var member = Storage.get('member');
            if(!member || !member.member_id){
                Storage.set('member', $scope.result);
            }
        });
        $rootScope.goToWineIndex = function(){
            $rootScope.showWineGlasses = true;
            $timeout(function(){
                $state.go('productIndex');
            },100);
        }
        //获取新闻列表
        Loading.showLoading();
        News.getNewsList();
        //读取资讯
        $scope.readMessage = function(messageId,fromWhere){
            News.saveFromWhere(fromWhere);
            $state.go('newsDetails',{'messageId':messageId});
        }
        //获取网络数据成功的后调用该方法
        $scope.$on('News.newsUpdated', function(){
            //隐藏加载框
            Loading.hideLoading();
            $scope.newsTopList = News.getTopNewsListJson();
            $scope.newsBottomList = News.getBottomNewsListJson();
            $scope.$broadcast('scroll.refreshComplete');
            //$ionicSlideBoxDelegate.$getByHandle('myHandle').update();
            $ionicSlideBoxDelegate.update();
        });
        $scope.doRefresh = function(){
            News.getNewsList();
        }
        $scope.loadMore = function(){
            News.getMoreNewsList();
        }
        $scope.$on('News.MoreNewsUpdated',function(){
            $scope.newsBottomList = News.getBottomNewsListJson();
            $scope.$broadcast('scroll.infiniteScrollComplete');
        });
        $scope.hasNextPage = function(){
            return News.hasNextPage();
        }
    });
